<template>
    <div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>单位名称</label>
            </div>
            <div>
                <p>{{formData.ProjectName}}</p>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>设备类型</label>
                <i class="iconfont icon-required"></i>
            </div>
            <div>
                <p>{{formData.EquipmentTypeName}}</p>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>自编号</label>
                <i class="iconfont icon-required"></i>
            </div>
            <div>
                <p>{{formData.EquipmentNo}}</p>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>是否自有设备</label>
                <i class="iconfont icon-required"></i>
            </div>
            <div>
                <p>{{formData.IsSelfEquipment}}</p>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>进场日期</label>
                <i class="iconfont icon-required"></i>
            </div>
            <div>
                <p>{{formData.EntryDate?formData.EntryDate.split(' ')[0]:''}}</p>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>验收日期</label>
                <i class="iconfont icon-required"></i>
            </div>
            <div>
                <p>{{formData.CheckDate?formData.CheckDate.split(' ')[0]:''}}</p>
            </div>
        </div>
        <div class="form-item form-item-style2">
            <div class="label-title">
                <label>参加验收人员</label>
                <i class="iconfont icon-required"></i>
            </div>
            <div>
                <p class="textarea">{{formData.CheckPerSonnel}}</p>
            </div>
        </div>
        <div class="form-item form-item-style2"
             v-if="formData.EquipmentTypeName == '其他'">
            <div class="label-title">
                <label>验收内容</label>
                <i class="iconfont icon-required"></i>
            </div>
            <div>
                <p class="textarea">{{formData.AcceptanceContent}}</p>
            </div>
        </div>
        <div class="cut-off-rule"></div>
        <div v-for="(items,key) in acceptanceItems"
             :key="key">
            <div class="cut-off-rule"></div>
            <div class="form-section">
                <h3 data-v-d3024438="">{{key | filterTitle}}</h3>
                <div class="form-item form-item-style1"
                     v-for="(item,index) in items"
                     :key="index">
                    <div class="label-title label-title1">
                        <label>{{item.AcceptanceItemName}}</label>
                        <i class="iconfont icon-required"></i>
                    </div>
                    <div class="select-section">
                        <div :class="{'active':item.AcceptanceItemResult == '是'}"
                             @click="changeItemResult(item,'是')">
                            是
                        </div>
                        <div :class="{'active':item.AcceptanceItemResult == '否'}"
                             @click="changeItemResult(item,'否')">
                            否
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="cut-off-rule"></div>
        <div class="form-section">
            <h3>
                验收图片
            </h3>
            <div class="form-item form-item-style2">
                <div class="label-title space-between">
                    <div class="space-between">
                        <label>图片</label>
                    </div>
                    <span>当前共{{imgList.length}}张</span>
                </div>
                <div class="upload-wrap">
                    <upload v-if="imgList.length"
                            :imgList="imgList"></upload>
                </div>
            </div>
            <div class="form-item form-item-style1">
                <div class="label-title">
                    <label>验证结论</label>
                </div>
                <div class="select-section">
                    <div :class="{'active': formData.IsResults == '1'}">
                        合格
                    </div>
                    <div :class="{'active': formData.IsResults == '0'}">
                        不合格
                    </div>
                </div>
            </div>
            <div class="form-item form-item-style2">
                <div class="label-title">
                    <label>验收意见</label>
                </div>
                <div>
                    <p class="textarea">{{formData.AcceptanceConclusion}}</p>
                </div>
            </div>
        </div>
        <myMenu></myMenu>
    </div>
</template>
<script>
import myMenu from '@/commonComponents/menu'
import upload from '@/commonComponents/upload/index'
export default {
    name: 'enterCheckDetail',
    data () {
        return {
            ImagesFiles: [],
            formData: {
                ID: '',
                EntryDate: '', // 进场时间
                CheckDate: '', // 验收时间
                IsResults: '1', // 验收结果1：合格 0不合格
                AcceptanceContent: '', // 验收内容（设备类型选择其他时）
                AcceptanceConclusion: '', // 验收意见
                CheckPerSonnel: '', // 验收人员
                EquipmentTypeNo: '', // 设备类型编号
                ItemList: []
            },
            acceptanceItems: {},
            imgList: [],
            userInfo: ''
        }
    },
    components: {
        upload,
        myMenu
    },
    filters: {
        filterTitle: function (val) {
            let title
            switch (val) {
                case 'BasicDataList':
                    title = '基本资料'
                    break
                case 'StructureList':
                    title = '塔吊结构'
                    break
                case 'RotationSystemList':
                    title = '绳轮转动系统'
                    break
                case 'AHookList':
                    title = '吊钩'
                    break
                case 'LimitInsuRanceList':
                    title = '限位保险'
                    break
                case 'DriveSystemList':
                    title = '机构传动系统'
                    break
                case 'PulleyList':
                    title = '卷筒滑轮'
                    break
                case 'ElectricalSystemList':
                    title = '司机室及电气系统'
                    break
                case 'BasicsList':
                    title = '基础'
                    break
                case 'SafeguardList':
                    title = '设备安全保护装置'
                    break
                case 'GearRackList':
                    title = '齿轮齿条'
                    break
                case 'GuideWayFrameList':
                    title = '导轨架'
                    break
                case 'WireropeList':
                    title = '钢丝绳与配重'
                    break
                case 'BoltList':
                    title = '螺栓及配件'
                    break
                case 'DriverElectricalSystemList':
                    title = '司机位与电气系统'
                    break
                case 'AppearanceCheckList':
                    title = '外观检查'
                    break
                case 'DriversCheckList':
                    title = '司机室检查'
                    break
                case 'TrackList':
                    title = '轨道检查'
                    break
                case 'SlingCheckList':
                    title = '吊具检查'
                    break
                case 'WireropeCheckList':
                    title = '钢丝绳检查'
                    break
                case 'PulleyCheckList':
                    title = '滑轮检查'
                    break
                case 'ElectricalSystemCheckList':
                    title = '电气系统检查'
                    break
                case 'HydraulicSystemCheckList':
                    title = '液压系统检查'
                    break
                case 'SafeguardCheckList':
                    title = '安全防护装置检查'
                    break
                case 'AppearanceChecList':
                    title = '外观检查'
                    break
                case 'SafetySystemList':
                    title = '安全系统'
                    break
                default:
                    title = ''
                    break
            }
            return title
        }
    },
    created () {
        this.$vux.loading.show({
            text: '加载中...'
        })
        this.userInfo = JSON.parse(localStorage.getItem('userInfo')) || {}
        this.formData.ID = this.$route.query.id
        this.getSiteAcceptanceDetails()
    },
    methods: {
        getSiteAcceptanceDetails () {
            let params = {
                'allowPaging': false,
                'business': 'getSiteAcceptanceDetails',
                'data': {
                    id: this.formData.ID
                },
                'pageIndex': 0,
                'pageSize': 20,
                'tokenId': '',
                'userId': this.userInfo.userid
            }
            this.$axiosAjax.getConfigJson(params).then((res) => {
                if (res.data.code === 0) {
                    let data = res.data.data
                    for (const key in data) {
                        if (data[key] instanceof Array && key !== 'ImagesFiles') {
                            this.acceptanceItems[key] = data[key]
                        } else if (!(data[key] instanceof Array)) {
                            this.formData[key] = data[key]
                        }
                    }
                    res.data.data.ImagesFiles.forEach(item => {
                        this.imgList.push(item)
                    })
                    this.$forceUpdate()
                }
            }).catch(() => {

            }).finally(() => {
                this.$vux.loading.hide()
            })
        }
    }
}
</script>
<style lang="less" scoped>
.label-title1 {
    width: 168px;
    line-height: 18px;
}
</style>
